package com.xxcloud.common.utils;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashSet;
import java.util.List;
import java.util.Random;
import java.util.Set;
import java.util.UUID;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class StringTools {
    public static boolean isNotBlank(Object s) {
        return s != null && isNotBlank(s.toString());
    }

    public static boolean isNotBlank(String s) {
        return s != null && s.trim().length() > 0;
    }

    public static boolean isBlank(String s) {
        return !isNotBlank(s);
    }

    public static boolean isBlank(Object s) {
        return s == null || !isNotBlank(s.toString());
    }

    /**
     * 对list进行升序，并返回指定obj值在列表中的下标
     *
     * @param list 无序列表
     * @param obj 目标值
     * @return obj在list升序列表的下标；list或者obj为空，或者不存在，都返回-1
     */
    public static int indexInListWithASC(List<Integer> list, Integer obj) {
        if (list == null || list.size() < 1 || obj == null) {
            return -1;
        }
        int rs = -1;
        Collections.sort(list, new Comparator<Integer>() {

            @Override
            public int compare(Integer o1, Integer o2) {
                if (o1 == null || o2 == null) {
                    return 0;
                }
                if (o1 > o2) {
                    return 1;
                }
                if (o1 < o2) {
                    return -1;
                }
                return 0;
            }
        });
        for (Integer o : list) {
            rs++;
            if (o.intValue() == obj.intValue()) {
                return rs;
            }
        }

        return rs;
    }

    /**
     * 在指定的列表list中，从随机下标开始，顺序返回count个list中的对象，到末尾就从0开始
     *
     * @param list 目标列表
     * @param count 指定返回的数量
     * @return
     */
    public static <T> List<T> randomList(List<T> list, int count) {
        try {
            if (list != null && list.size() > count) {
                List<T> rs = new ArrayList<T>();
                int size = list.size();
                Random r = new Random(System.nanoTime());
                int start = r.nextInt(size);
                for (int i = 0; i < count; i++) {

                    rs.add(list.get(start % size));
                    start++;
                }
                return rs;
            }
            return list;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return list;
    }

    /**
     * 删除字符中的HTML标签
     *
     * @param htmlStr
     * @return
     */
    private static final String REGEX_SCRIPT = "<script[^>]*?>[\\s\\S]*?<\\/script>"; // 定义script的正则表达式
    private static final String REGEX_STYLE = "<style[^>]*?>[\\s\\S]*?<\\/style>"; // 定义style的正则表达式
    private static final String REGEX_HTML = "<[^>]+>"; // 定义HTML标签的正则表达式

    public static String delHTMLTag(String htmlStr) {
        if (isBlank(htmlStr)) {
            return "";
        }

        Pattern p_script = Pattern.compile(REGEX_SCRIPT, Pattern.CASE_INSENSITIVE);
        Matcher m_script = p_script.matcher(htmlStr);
        htmlStr = m_script.replaceAll(""); // 过滤script标签

        Pattern p_style = Pattern.compile(REGEX_STYLE, Pattern.CASE_INSENSITIVE);
        Matcher m_style = p_style.matcher(htmlStr);
        htmlStr = m_style.replaceAll(""); // 过滤style标签

        Pattern p_html = Pattern.compile(REGEX_HTML, Pattern.CASE_INSENSITIVE);
        Matcher m_html = p_html.matcher(htmlStr);
        htmlStr = m_html.replaceAll(""); // 过滤html标签

        return htmlStr.trim(); // 返回文本字符串
    }

    /**
     * 指定的字符串是否满足指定的正则表达式定义
     *
     * @param s 目标字符串
     * @param p 正则定义
     * @return
     */
    public static boolean isMatch(String s, Pattern p) {
        if (isBlank(s)) {
            return false;
        }
        return p.matcher(trimAllBlanks(s)).matches();
    }

    /**
     * 删除字符串中所有半角空格
     *
     * @param s
     * @return
     */
    public static String trimAllBlanks(String s) {
        if (isBlank(s)) {
            return "";
        }
        return s.replaceAll("\\s", "");
    }

    /**
     * 判断字符串是否仅由数字和字符串组成
     * 
     * @param s
     * @return
     */
    public static boolean isNumberOrLetters(String s) {
        if (isBlank(s)) {
            return false;
        }
        return StaticValue.Regex.NUMBER_OR_LETTER.matcher(trimAllBlanks(s)).matches();
    }

    /**
     * 字符串是否全部是英文字母
     *
     * @param s
     * @return
     */
    public static boolean isLetters(String s) {
        if (isBlank(s)) {
            return false;
        }
        return StaticValue.Regex.LETTERS.matcher(trimAllBlanks(s)).matches();
    }

    /**
     * 判断字符串是否全部是中文汉字 <br />
     * 半角空格不参与判断
     * 
     * @param s
     * @return
     */
    public static boolean isAllChineseWord(String s) {
        if (isBlank(s)) {
            return false;
        }
        return StaticValue.Regex.CHINESE_WORD.matcher(trimAllBlanks(s)).matches();
    }

    /**
     * 判断字符串是否包含中文汉字 <br />
     * 半角空格不参与判断<br />
     * 全部是汉字，也返回true
     * 
     * @param s
     * @return
     */
    public static boolean isContainChineseWord(String s) {
        if (isBlank(s)) {
            return false;
        }
        return StaticValue.Regex.CONTAIN_CHINESE_WORD.matcher(trimAllBlanks(s)).matches();
    }

    /**
     * 汉字的code codePointAt <br />
     * “猎”的code为29454，“上”的code为19978；“猎上”和“上猎”都返回：19978_29454
     * 
     * @param s
     * @return 返回汉字code升序之后，下划线连接
     */
    public static String stringToCharCode(String s) {
        if (isBlank(s)) {
            return s;
        }
        s = s.toLowerCase();

        if (isNumberOrLetters(s)) {// 没有汉字
            return s;
        }
        List<Integer> codes = new ArrayList<Integer>();
        for (int i = 0, len = s.length(); i < len; i++) {
            int cv = s.codePointAt(i);
            if (cv == 32) {
                continue;
            }
            codes.add(cv);
        }
        Collections.sort(codes, StaticValue.INTEGER_COMPARATOR_ASC);

        return join(codes, StaticValue.SpliteAndChar.UNDERLINE);
    }

    /**
     * 用于显示，多个空格合并成一个空格
     * 
     * @param word
     * @return
     */
    public static String withOneSpace(String word) {
        return cleanSpecailAndRepalceBlanksWith(word, StaticValue.SpliteAndChar.ONE_BLANK);
    }

    /**
     * 多个空格由一个自定义特殊字符代替，用于索引
     * 
     * @param word
     * @return
     */
    public static String withReplaceSpace(String word) {
        return cleanSpecailAndRepalceBlanksWith(word, StaticValue.ReplaceString.SPECIAL_SPLIT);
    }

    /**
     * 删除字符串w中 数字、英文、汉字、-、+、# 之外的字符，并且将多个空格替换成指定的字符串<br />
     * [^a-zA-Z|\u4e00-\u9fa5|\\d|\\-|\\+|\\#]
     * 
     * @param w 目标字符串，先会转为半角
     * @param sp 指定的字符串
     * @return
     */
    public static String cleanSpecailAndRepalceBlanksWith(String w, String sp) {
        try {
            String temp = toDBC(w);
            temp = temp.replaceAll(StaticValue.ReplaceString.AUTOKEY_FILTER, " ").toLowerCase();
            return temp.trim().replaceAll("\\s+", sp);
        } catch (Exception e) {
            return w;
        }
    }

    /**
     * 删除字符串w中 数字、英文、汉字、-、+、# 之外的字符，并且将多个空格替换成指定的字符串<br />
     * [^a-zA-Z|\u4e00-\u9fa5|\\d|\\-|\\+|\\#]
     * 
     * @param w 目标字符串，先会转为半角
     * @param sp 指定的字符串
     */
    @Deprecated
    public static String replace(String w, String sp) {
        return cleanSpecailAndRepalceBlanksWith(w, sp);
    }

    private static final String PATTERN_FOR_CLEAR = "[||\\(|\\)]?";

    /**
     * 清理自动提示关键字<br />
     * 清理内容：| \ ( )
     * 
     * @param w
     * @return
     */
    public static String clearAutoKeyWord(String w) {
        try {
            if (w == null)
                return null;
            String temp = toDBC(w);
            temp = temp.replaceAll(StaticValue.ReplaceString.AUTOKEY_FILTER, StaticValue.SpliteAndChar.ONE_BLANK);

            temp = temp.replaceAll("\\-", StaticValue.SpliteAndChar.ONE_BLANK);

            return temp.replaceAll(PATTERN_FOR_CLEAR, "").trim().replaceAll("\\s+", StaticValue.SpliteAndChar.ONE_BLANK);
        } catch (Exception e) {
            return w;
        }
    }

    /**
     * 初始输入关键字清理<br />
     * 清理内容：[^a-zA-Z|\u4e00-\u9fa5|\\d|\\-|\\+|\\s|\\@|\\!|\\！|\\.]
     * 
     * @param w
     * @return
     */
    public static String cleanQueryWord(String w) {
        try {
            String temp = toDBC(w);
            temp = temp.replaceAll(StaticValue.ReplaceString.INPUT_KEYWORD, StaticValue.SpliteAndChar.ONE_BLANK).toLowerCase();
            // temp = temp.replaceAll("\\s*\\-+\\s*", " -");
            temp = temp.replaceAll("\\s+", StaticValue.SpliteAndChar.ONE_BLANK);
            return temp.trim();
        } catch (Exception e) {
            return w;
        }
    }

    /**
     * 字符串是否重复 ，按空格分词
     * 
     * @param vals
     * @return
     */
    private static boolean isRepeatSpliteBySpace(String[] vals) {
        Set<String> set = new HashSet<String>(vals.length);

        for (String v : vals) {
            if (v.trim().length() > 0) {
                if (!set.contains(v)) {
                    set.add(v);
                } else {
                    return true;
                }
            }
        }

        return false;
    }

    /**
     * 字符串是否单字重复
     * 
     * @param s
     * @return
     */
    private static boolean isRepeatSingleWord(String s) {
        Set<Character> set = new HashSet<Character>(s.length());
        int repeatCount = 0;
        for (int i = 0, len = s.length(); i < len; i++) {
            char ch = s.charAt(i);
            if (!set.contains(ch)) {
                set.add(ch);
            } else {
                repeatCount++;
            }
        }

        return (float) repeatCount / (float) s.length() >= 0.2;
    }

    /**
     * 对关键字进行简单的去重复 “女 女装 衬衫” ---> “女装 衬衫”
     * 
     * @param w
     * @return
     */
    public static String replaceSameWord(String w) {
        if (isBlank(w)) {
            return "";
        }
        try {
            String[] ws = w.split(" ");
            List<String> rs = Arrays.asList(ws);
            Collections.sort(rs, new Comparator<String>() {
                public int compare(String o1, String o2) {
                    return o2.length() - o1.length();
                }

            });
            StringBuilder sb = new StringBuilder("");
            for (String s : rs) {
                if (s != null && !s.isEmpty() && sb.indexOf(s) < 0) {
                    sb.append(s + " ");
                }
            }
            return sb.toString().trim();
        } catch (Exception e) {
            return w;
        }
    }

    /**
     * 关键字是否有一定的重复性
     * 
     * @param l
     * @return
     */
    public static boolean isRepeatMany(String l) {
        if (l == null) {
            return false;
        }
        String[] vals = l.split(" ");
        boolean rs = isRepeatSpliteBySpace(vals);
        if (rs) {
            return rs;
        }

        return isRepeatSingleWord(l);
    }

    /**
     * 全角转半角
     * 
     * @param input
     * @return
     */
    public static String toDBC(String input) {
        char[] c = input.toCharArray();
        for (int i = 0; i < c.length; i++) {
            if (c[i] == 12288) {
                c[i] = (char) 32;
                continue;
            }
            if (c[i] > 65280 && c[i] < 65375)
                c[i] = (char) (c[i] - 65248);
        }
        return new String(c);
    }

    /**
     * 返回有效值<br />
     * 如果value在min和max之间，则返回value，否则返回dft
     * 
     * @param value
     * @param min
     * @param max
     * @param dft
     * @return
     */
    public static long valueAsDefault(long value, long min, long max, long dft) {
        return value >= min && value <= max ? value : dft;
    }

    /**
     * 返回有效值<br />
     * 如果value在min和max之间，则返回value，否则返回dft
     * 
     * @param value
     * @param min
     * @param max
     * @param dft
     * @return
     */
    public static int valueAsDefault(int value, int min, int max, int dft) {
        return value >= min && value <= max ? value : dft;
    }

    /**
     * @deprecated 目前没啥用的方法，如有需要重新写
     * @param input
     * @return
     * @see [相关类/方法](可选)
     * @since [产品/模块版本](可选)
     */
    @Deprecated
    public static List<String> pickString(String input) {
        List<String> rs = new ArrayList<String>(0);
        try {
            if (isBlank(input)) {
                return rs;
            }

            Matcher m = StaticValue.Regex.ID_SN_PATTERN_END.matcher(input);

            while (m.find()) {
                rs.add(m.group(1));
            }
            if (rs.size() < 1) {
                m = StaticValue.Regex.ID_SN_PATTERN.matcher(input);
                while (m.find()) {
                    rs.add(m.group(1));
                }
            }
            return rs;
        } catch (Exception e) {
            return rs;
        }
    }

    /**
     * 把字符串通过分隔符英文逗号进行分割 功能描述: <br>
     * 〈功能详细描述〉
     *
     * @param ids
     * @return
     * @see [相关类/方法](可选)
     * @since [产品/模块版本](可选)
     */
    public static String[] stringToStringArray(String ids) {
        if (isBlank(ids)) {
            return new String[0];
        }
        String[] temp = ids.split(StaticValue.SpliteAndChar.COMMA);
        return temp;
    }

    /**
     * 内部类的list转为ArrayList
     *
     * @param list
     * @return
     */
    public static <T> List<T> internalListToArrayList(List<T> list) {
        if (list == null || list.size() == 0) {
            return list;
        }
        List<T> rs = new ArrayList<T>(list.size());

        for (T v : list) {
            rs.add(v);
        }

        return rs;
    }

    /**
     * 将数组转为ArrayList 功能描述: <br>
     * 〈功能详细描述〉
     *
     * @param array
     * @return
     * @see [相关类/方法](可选)
     * @since [产品/模块版本](可选)
     */
    public static <T> List<T> arrayToArrayList(T[] array) {
        if (array == null) {
            return null;
        }
        int length = array.length;
        if (length == 0) {
            return new ArrayList<>(0);
        }
        List<T> rs = new ArrayList<T>(length);
        for (T v : array) {
            rs.add(v);
        }
        return rs;
    }

    /**
     * 字符串转为ArrayList，英文逗号分割
     *
     * @param ids
     * @return
     */
    public static List<String> stringToStringList(String ids) {
        String[] temp = stringToStringArray(ids);
        return arrayToArrayList(temp);
    }

    /**
     * 将字符串按照英文逗号分割，并转为Long型的ArrayList
     *
     * @param ids 英文逗号分割的字符串
     * @return
     */
    public static List<Long> stringToLongList(String ids) {
        return stringToLongList(ids, StaticValue.SpliteAndChar.COMMA);
    }

    /**
     * 将字符串按照英文逗号分割，并转为Integer型的ArrayList
     *
     * @param ids 英文逗号分割的字符串
     * @return
     */
    public static List<Integer> stringToIntegerList(String ids) {
        return stringToIntegerList(ids, StaticValue.SpliteAndChar.COMMA);
    }

    public static void main(String[] args) {
        System.out.println(stringToIntegerList(null));

        System.out.println(toDBC("中午").length());
    }

    /**
     * 将字符串分割，转为Integer型的ArrayList
     *
     * @param ids 英文逗号分割的字符串
     * @param reg 自定义分隔符
     * @return
     */
    public static List<Integer> stringToIntegerList(String ids, String reg) {
        if (ids == null || ids.length() == 0) {
            return new ArrayList<Integer>(0);
        }
        String[] temp = ids.split(reg);
        List<Integer> rs = new ArrayList<Integer>(ids.length());
        for (String s : temp) {
            Integer sL = StringFormat.getInt(s, null);
            if (sL != null) {
                rs.add(sL);
            }
        }
        return rs;
    }

    public static List<Long> stringToLongList(List<String> ids) {
        if (ids == null || ids.size() < 1) {
            return new ArrayList<Long>(0);
        }
        List<Long> rs = new ArrayList<Long>(ids.size());
        for (String s : ids) {
            Long sL = StringFormat.getLong(s, null);
            if (sL != null) {
                rs.add(sL);
            }
        }
        return rs;
    }

    /**
     * 将字符串分割，转为Long型的ArrayList
     *
     * @param ids
     * @param reg 自定义的分隔符
     * @return
     * @see [相关类/方法](可选)
     * @since [产品/模块版本](可选)
     */
    public static List<Long> stringToLongList(String ids, String reg) {
        List<Long> rs = new ArrayList<Long>(0);
        if (ids == null || ids.length() == 0) {
            return rs;
        }
        String[] ss = ids.split(reg);
        if (ss.length > 0) {
            rs = new ArrayList<Long>(ss.length);
            for (String s : ss) {
                Long sL = StringFormat.getLong(s, null);
                if (sL != null) {
                    rs.add(sL);
                }
            }
        }
        return rs;
    }

    public static List<Integer> stringToIntList(String ids, String regex) {
        if (ids == null || ids.length() == 0) {
            return new ArrayList<Integer>(0);
        }
        String[] ss = ids.split(regex);
        if (ss.length > 0) {
            List<Integer> rs = new ArrayList<>(ss.length);
            for (String s : ss) {
                Integer sL = StringFormat.getInt(s, null);
                if (sL != null) {
                    rs.add(sL);
                }
            }
        }
        return new ArrayList<>(0);
    }

    public static <T> String join(List<T> values, String sep) {
        StringBuilder sb = new StringBuilder("");

        if (values != null && values.size() > 0) {
            for (T o : values) {
                if (o != null) {
                    sb.append(o.toString()).append(sep);
                }
            }
            if (sb.length() > 0) {
                sb.delete(sb.length() - sep.length(), sb.length());
            }
        }

        return sb.toString();
    }

    public static <T> List<T> subList(List<T> list, int limit) {
        if (list == null || list.size() < 1) {
            return new ArrayList<T>();
        }
        int size = list.size();
        if (size > limit) {
            List<T> rs = new ArrayList<>(limit);
            int c = 1;
            for (T t : list) {
                rs.add(t);
                if (c++ >= limit) {
                    break;
                }
            }
            return rs;
        }
        return list;
    }

    public static final char[] ender = new char[] { '-', '—', '－', '–', '/', '(' };

    public static String cleanPositionTitle(String title) {

        for (char ch : ender) {
            int v = title.indexOf(ch);
            if (v > 1) {
                title = title.substring(0, v).trim();
            }
        }

        return title;
    }

    static Pattern regexLetter = Pattern.compile("[\\S|\\s|\n]*?([a-zA-Z|\\+|\\#|\\d|\\s]+)[\\S|\\s|\n]*\\S*");

    public static String getMainWordFromTitle(String line) {
        return getRegexString(line, regexLetter);
    }

    public static String getRegexString(String line, Pattern p) {
        if (isBlank(line)) {
            return "";
        }
        try {
            Matcher ma = p.matcher(line.replaceAll("\\s+", " "));
            while (ma.matches()) {
                return ma.group(1);
            }
            return ma.group(1);
        } catch (Exception e) {
            return "";
        }
    }

    /**
     * 将字符串按照指定分隔符分割，然后获取指定位置的值
     *
     * @param line 目标字符串
     * @param sep 分隔符
     * @param index 下标，0开始
     * @return
     */
    public static String splitAndGet(String line, String sep, int index) {
        if (isBlank(line)) {
            return line;
        }
        String[] values = line.split(sep);
        if (values.length >= index) {
            for (int i = index, len = values.length; i < len; i++) {
                String v = values[i].trim();
                if (v.length() > 1) {
                    return v;
                }
            }
        }
        return line;
    }

    public static boolean isLettersOrSymbol(String s) {
        if (isBlank(s)) {
            return false;
        }
        return LETTERS_AND_SYMBOL.matcher(trimAllBlanks(s)).matches();
    }

    private final static Pattern LETTERS_AND_SYMBOL = Pattern.compile("[\\w+|\\d|\\.|\\+|\\#]+");

    public final static Pattern NUMBERS = Pattern.compile(".*(\\d+).*");

    public static boolean isNumeric(String s) {
        if (!isNotNull(s))
            return false;
        return StaticValue.Regex.NUMERIC.matcher(s).matches();
    }

    public static Integer getInt(String v, int dft) {
        return StringFormat.getInt(v, dft);
    }

    public static Integer getIntWithDelete(String v, int dft) {
        if (isBlank(v)) {
            return dft;
        }
        return getInt(v.replaceAll(StaticValue.Regex.NO_NUMERIC.pattern(), ""), dft);
    }

    public static Integer getInt(Object o, int dft) {
        return StringFormat.getInt(o, dft);
    }

    public static Float getFloat(String v, float dft) {
        return StringFormat.getFloat(v, dft);
    }

    public static Float getFloat(Object o, float dft) {
        return StringFormat.getFloat(o, dft);
    }

    public static Double getDbl(String v, Double dft) {
        return StringFormat.getDbl(v, dft);
    }

    public static Double getDbl(Object o, Double dft) {
        return StringFormat.getDbl(o, dft);
    }

    public static boolean isNumber(String s) {
        if (!isNotNull(s))
            return false;
        return StaticValue.Regex.NUMBER.matcher(s).matches();
    }

    public static Long getLong(String v, long dft) {
        return StringFormat.getLong(v, dft);
    }

    public static Long getLong(Object v, long dft) {
        return StringFormat.getLong(v, dft);
    }

    public static Boolean getBoolean(String v, boolean dft) {
        return StringFormat.getBoolean(v, dft);
    }

    public static Boolean getBoolean(Boolean v, boolean dft) {
        if (v == null) {
            return dft;
        }
        return v;
    }

    public static boolean isNotNull(String v) {
        return v != null && !v.trim().isEmpty();
    }

    public static String getString(String s, String dft) {
        if (isNotNull(s)) {
            return s;
        }
        return dft;
    }

    public static Integer getIntFromBoolean(String v, int trueInt, int falseInt) {
        return StringFormat.getIntFromBoolean(v, trueInt, falseInt);
    }

    public static String join(Collection<Object> values, String sep) {
        StringBuilder sb = new StringBuilder("");

        if (values != null && values.size() > 0) {
            for (Object o : values) {
                sb.append(o.toString()).append(sep);
            }
            if (sb.length() > 0) {
                sb.deleteCharAt(sb.length() - sep.length());
            }
        }

        return sb.toString();
    }

    public static String joinList(List<Long> values, String sep) {
        StringBuilder sb = new StringBuilder("");

        if (values != null && values.size() > 0) {
            for (Long o : values) {
                sb.append(o.toString()).append(sep);
            }
            if (sb.length() > 0) {
                sb.deleteCharAt(sb.length() - sep.length());
            }
        }

        return sb.toString();
    }

    /**
     * 验证手机号码
     *
     * @return
     */
    public static boolean isMobilePhone(String mobiles) {
        if (isBlank(mobiles)) {
            return false;
        }
        Matcher m = StaticValue.Regex.MOBILE_PHONE.matcher(mobiles);
        return m.matches();
    }

    /**
     * 验证邮箱
     *
     * @param email
     * @return
     */
    public static boolean isEmail(String email) {
        boolean flag = false;
        if (isBlank(email)) {
            return flag;
        }
        try {
            Matcher matcher = StaticValue.Regex.EMAIL.matcher(email);
            flag = matcher.matches();
        } catch (Exception e) {
            flag = false;
        }
        return flag;
    }

    public static String formatNumForPlus(Integer actualCount, Integer maxCount, String plusString) {
        if (actualCount == null) {
            return "";
        }

        if (maxCount != null && actualCount >= maxCount) {
            return maxCount + plusString;
        }
        return actualCount.toString();
    }

    public static String formatNumForPlus(Long actualCount, Integer maxCount, String plusString) {
        if (actualCount == null) {
            return "";
        }

        return formatNumForPlus(actualCount.intValue(), maxCount, plusString);
    }

    public static String randomUUID() {
        return UUID.randomUUID().toString().replaceAll("-", "");
    }

    public static boolean isLetter(Character ch) {
        int v = ch - 0;
        return (v >= 65 && v <= 90) || (v >= 97 && v <= 122);
    }

    public static boolean isNumber(Character ch) {
        int v = ch - 0;
        return v >= 48 && v <= 57;
    }

    // 是否可成词判断
    public static boolean canBeFinalWord(Character prev, String word, Character ch) {
        if (isBlank(word)) {
            return false;
        }

        char wordFirstChar = word.charAt(0);
        if (isLetter(wordFirstChar) || isNumber(wordFirstChar)) {
            // 如果关键字首字是数字，英文
            if (prev != null && (isLetter(prev) || isNumber(prev))) {
                return false;
            }
        }

        char wordEndChar = word.charAt(word.length() - 1);
        if (isLetter(wordEndChar) || isNumber(wordEndChar)) {
            // 如果关键字首字是数字，英文
            if (ch != null && (isLetter(ch) || isNumber(ch))) {
                return false;
            }
        }

        return true;
    }

    public static List<String> createFromLine(String line, String sep) {
        List<String> result = new ArrayList<>(5);
        String[] lines = line.split(sep);
        String prev = lines[0];

        String after = lines[1];

        String[] prevs = prev.split(",");
        String afters[] = after.split(",");
        for (String pv : prevs) {
            for (int i = 0, len = afters.length; i < len; i++) {
                String newWord = pv + afters[i];
                result.add(newWord);
            }
        }
        return result;
    }

}
